package com.coolbi.security.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.coolbi.security.dao.RolesDao;
import com.coolbi.security.entity.Roles;
import com.coolbi.security.mapper.RolesMapper;

public class RolesDaoImpl implements RolesDao {

	@Autowired
	private RolesMapper rolesMapper;
	public void setRolesMapper(RolesMapper rolesMapper) {
		this.rolesMapper = rolesMapper;
	}

	@Override
	public List<Roles> find(Map<String, Object> parameter) {
		return rolesMapper.listByParameter(parameter);
	}

	@Override
	public List<Roles> find(Map<String, Object> parameter, int offset, int limit) {
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return rolesMapper.listByParameterPage(parameter);
	}

	@Override
	public int count(Map<String, Object> parameter) {
		return rolesMapper.countByParameter(parameter);
	}

	@Override
	public List<Roles> search(String keyword, int offset, int limit) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("keyword", keyword);
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return rolesMapper.search(parameter);
	}

	@Override
	public int countByKeyword(String keyword) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("keyword", keyword);
		return rolesMapper.countByKeyword(parameter);
	}

	@Override
	public Roles save(Roles obj) {
		rolesMapper.save(obj);
		return obj;
	}

	@Override
	public int update(Roles obj) {
		return rolesMapper.update(obj);
	}

	@Override
	public int delete(long id) {
		return rolesMapper.delete(id);
	}

	@Override
	public Roles get(long id) {
		return rolesMapper.get(id);
	}

	@Override
	public List<Roles> list() {
		return rolesMapper.list();
	}

	@Override
	public List<Roles> list(int offset, int limit) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return rolesMapper.listByPage(parameter);
	}

	@Override
	public int count() {
		return rolesMapper.count();
	}

	@Override
	public int countByName(String name) {
		return rolesMapper.countByName(name);
	}

	@Override
	public int countByAuthority(String authority) {
		return rolesMapper.countByAuthority(authority);
	}
}
